/*
 * Copyright (C) 2011 Dirk Weißenborn, dirk.weissenborn@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.weissenborn.colabtex.client.service;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * The Interface LoginService.
 */
@RemoteServiceRelativePath("UserManagementService")
public interface UserManagementService extends RemoteService {
	
	/**
	 * Login.
	 *
	 * @param userId the user id
	 * @param password the password
	 * @return the session id (token)
	 */
	public String login(String userId, String password);
	
	/**
	 * Gets the user.
	 *
	 * @param sessionID the session id
	 * @return the user
	 */
	public String getUser(String sessionID);
	
	/**
	 * Inits shiro service for authentication
	 */
	public void initShiro();
	
	/**
	 * Logout.
	 *
	 * @param sessionID the session id
	 */
	public void logout(String sessionID);
	
	/**
	 * Delete user.
	 *
	 * @param id the id
	 * @param password the password
	 */
	public void deleteUser(String id, String password);
	
	/**
	 * Register.
	 *
	 * @param email the email = id
	 * @return whether user was registered or not
	 */
	public Boolean register(String email);
	
	/**
	 * Reset password.
	 *
	 * @param email the email = id
	 * @return whether password was reseted or not
	 */
	public Boolean resetPassword(String email);
	
	/**
	 * Sets the new password.
	 *
	 * @param email the mail address = id
	 * @param password the password
	 * @param newPassword the new password
	 * @return whether password was reseted or not
	 */
	public Boolean setNewPassword(String email, String password, String newPassword);
	
	/**
	 * Sets the new email.
	 *
	 * @param oldAddress the old address = id
	 * @param newAddress the new address = id
	 * @param password the password
	 * @return whether email = id set or not
	 */
	public Boolean setNewEmail(String oldAddress, String newAddress, String password);
	
	/**
	 * The Class Util.
	 */
	public static class Util {
		
		/** The instance. */
		private static UserManagementServiceAsync instance;
		
		/**
		 * Gets the single instance of Util.
		 *
		 * @return single instance of Util
		 */
		public static UserManagementServiceAsync getInstance(){
			if (instance == null) {
				instance = GWT.create(UserManagementService.class);
			}
			return instance;
		}		
		
	}
}
